home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac 1 / Ian and Stuart's One (Australia).iso / Australasian Legends / Commercial / Rainbow Hill / MacDOS™ 2.0.0 / filters / filter projects / filters.c < prev    next >
C/C++ Source or Header  |  1994-05-27  |  3KB  |  116 lines

  1. /*
  2.  *    filters.c    Some MacDOS filters.
  3.  *
  4.  *    Released MacDOS 1.0.1a on 94/01/31
  5.  *    94/05/27    File created by copying filter.c
  6.  *    94/05/27    First version completed
  7.  *
  8.  *--------------------------------------------------------------------------------------------------
  9.  *    Copyright © 1994 by Rainbow Hill Pty Ltd.
  10.  *
  11.  *    This program is free software; you can redistribute it and/or modify it under the terms of
  12.  *    the GNU General Public License as published by the Free Software Foundation; either version 2
  13.  *    of the License, or any later version.
  14.  *
  15.  *    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  16.  *    without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17.  *    See the GNU General Public License for more details.
  18.  *
  19.  *    You should have received a copy of the GNU General Public License along with this program;
  20.  *    if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23. #include <Errors.h>
  24. #include "pipe.h"
  25.  
  26. #define doNothing        0
  27. #define multiplyLines    1
  28. #define countLines        2
  29.  
  30. #define doThis            0        /* adjust this value to select the filtering */
  31.  
  32. static pipeParmsFun_t    HandleParameters;
  33.  
  34. /*
  35.  *    global variable definitions
  36. */
  37. #if doThis == multiplyLines
  38.     static short    nTimes;
  39.  
  40. #endif
  41.  
  42. main() {
  43.     OSErr            os_err;
  44.     unsigned char    inBuff[pipeSize];
  45.     unsigned char    outBuff[pipeSize];
  46.  
  47.     /* initialisation */
  48.     MaxApplZone();
  49.     InitGraf(&thePort);
  50.     InitWindows();
  51.     InitDialogs(0L);
  52.     InitCursor();
  53.  
  54.     /* initialise the incoming pipe */
  55.     PipeInit(HandleParameters);
  56.  
  57.     /* keep getting records from the master as long as no error occurs */
  58.     while (true) {
  59.  
  60.         /* wait to receive the next record */
  61.         PipePoll(inBuff);
  62.  
  63.         /*
  64.          *    filtering
  65.          */
  66. #        if doThis == doNothing
  67.         {    /* just copy the input to the output */
  68.             PipeSendData(inBuff);
  69.             }
  70.  
  71. #        elif doThis == multiplyLines
  72.         {    /* repeates the input lines a fixed number of times */
  73.             short k;
  74.  
  75.             for (k = nTimes; k > 0; k--) PipeSendData(inBuff);
  76.             }
  77.  
  78. #        elif doThis == countLines
  79.         {    /* count the lines and send out the number when receiving an empty line */
  80.             static long k = 0L;
  81.  
  82.             if (inBuff[0] > 0) {
  83.                 k++;
  84.                 PipeSendData("\p");
  85.                 }
  86.             else {
  87.                 NumToString(k, inBuff);
  88.                 inBuff[inBuff[0] + 1] = '\r';
  89.                 inBuff[0]++;
  90.                 PipeSendData(inBuff);
  91.                 }
  92.             }
  93.  
  94. #            endif
  95.         }
  96.     } /* main */
  97.  
  98. /*------------------------------------------------------------------------------ HandleParameters */
  99. static OSErr HandleParameters(unsigned char *parms) {
  100.  
  101. #    if doThis == multiplyLines
  102.     {
  103.         long    aLong;
  104.  
  105.         StringToNum(parms, &aLong);
  106.         if (aLong <= 0L)
  107.             nTimes = 1;
  108.         else
  109.             nTimes = (short)aLong;
  110.         }
  111.  
  112. #        endif
  113.  
  114.     return (noErr);
  115.     } /* HandleParameters */
  116.